package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.SignUpRegister;
import com.eling.elcms.travel.model.TravelContract;
import com.eling.elcms.travel.model.view.SignUpChargeStatusView;
import com.eling.elcms.travel.model.view.SignUpRegisterSaveView;
import com.eling.elcms.travel.model.view.SignUpRegisterView;
import com.eling.elcms.travel.service.ISignUpRegisterManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
public class SignUpRegisterController extends BaseFormController {
	@Autowired
	private ISignUpRegisterManager signUpRegisterManager;

	@RequestMapping("/api/signupregister/save")
	@ResponseBody
	public SignUpRegister save(@ModelAttribute @ModelFilling SignUpRegister signUp) {
		return signUpRegisterManager.save(signUp);
	}

	@RequestMapping("/api/signupregister/query")
	@ResponseBody
	public List<SignUpRegister> query(@ModelAttribute SignUpRegister signUp) {
		List<SignUpRegister> query = signUpRegisterManager.query(signUp);
		List<SignUpRegister> signList = new ArrayList<>();
		for (SignUpRegister signUpRegister : query) {
			if(signUpRegister.getExitGroup()==null||signUpRegister.getExitGroup()!=true){
				signList.add(signUpRegister);
			}
		}
		return signList;
	}

	@RequestMapping("/api/signupregister/queryall")
	@ResponseBody
	public List<SignUpRegisterView> queryAll(@ModelAttribute @ModelFilling SignUpRegister signUp,
										@RequestParam(value="payFul",required=false)String payFul) {
		return signUpRegisterManager.queryAll(signUp,payFul);
	}

	@RequestMapping("/api/signupregister/search*")
	@ResponseBody
	public List<SignUpRegister> search(@ModelAttribute SearchCondition sc, @ModelAttribute SignUpRegister signUp) {
		sc.setQueryCondition(signUp);
		return signUpRegisterManager.search(sc);
	}

	@RequestMapping("/api/signupregister/{pkSignUpRegister}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkSignUpRegister) {
		signUpRegisterManager.remove(pkSignUpRegister);
		return new Msg("删除成功");
	}

	@RequestMapping("/api/signupregister/querycertificates")
	@ResponseBody
	public List<TravelContract> querycertificates(@ModelAttribute SearchCondition sc,
			@ModelAttribute @ModelFilling SignUpRegister signUp,
			@RequestParam(value = "pkServicePoint", required = false) Long pkServicePoint) {
		return signUpRegisterManager.querycertificates(sc, signUp, pkServicePoint);
	}

	@RequestMapping("/api/signupregister/saveall")
	@ResponseBody
	public List<SignUpRegister> saveAll(@ModelAttribute SignUpRegisterSaveView signUp) {
		return signUpRegisterManager.saveAll(signUp);
	}

	@RequestMapping("/api/signupregister/{pkSignUpRegister}/deletenonmembergroup")
	@ResponseBody
	public Msg deleteNonMemberGroup(@PathVariable Long pkSignUpRegister) {
		return signUpRegisterManager.deleteNonMemberGroup(pkSignUpRegister);
	}

	@RequestMapping("/api/signupregister/savecustomer")
	@ResponseBody
	public SignUpRegister saveCustomer(@ModelAttribute SignUpRegister signUp,
			@RequestParam(value = "checkInDate", required = false) Date checkInDate,
			@RequestParam(value = "checkOutDate", required = false) Date checkOutDate,
			@RequestParam(value = "pkPersonalInfo", required = false) Long pkPersonalInfo) {
		return signUpRegisterManager.saveCustomer(signUp,checkInDate,checkOutDate,pkPersonalInfo);
	}

	/**
	 * 查询报名人员的收费状态
	 * 
	 * @param pkPlanItemGroup
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/signupregister/querychargestatus")
	@ResponseBody
	public List<SignUpChargeStatusView> queryChargeStatus(
			@RequestParam(value = "pkPlanItemGroup", required = false) Long pkPlanItemGroup) {
		return signUpRegisterManager.queryChargeStatus(pkPlanItemGroup);
	}

	@RequestMapping("/api/signupregister/adjustaddsignup")
	@ResponseBody
	public Map<String, Object> adjustAddSignUp(
			@RequestParam(value = "pkGroup", required = false) Long pkGroup,
			@RequestParam(value = "dataSource", required = false) String dataSource,
			@ModelAttribute SignUpRegister signUp) {
		return signUpRegisterManager.adjustAddSignUp(pkGroup, dataSource, signUp);
	}
}
